package com.doudou.collection.controller;

import com.doudou.collection.mapper.BlogMapper;
import com.doudou.collection.pojo.dto.BlogDTO;
import com.doudou.collection.pojo.entity.Blog;
import com.doudou.collection.pojo.vo.BlogCategoriesVO;
import com.doudou.collection.pojo.vo.BlogDetailVO;
import com.doudou.collection.pojo.vo.ContentIndexVO;
import com.doudou.collection.response.ResultVO;
import com.doudou.collection.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @ClassName BlogController<br>
 * @Description 博客文章管理模块<br>
 * @Author 李浩文<br>
 * @Date 2023/6/2 16:02<br>
 * @Version 1.0<br>
 */
@Api(tags = "02.博客文章管理模块")
@Slf4j
@RestController
@RequestMapping("/v1/blogs/")
public class BlogController {



    @Autowired
    private BlogService blogService;

    @ApiOperation("根据分类id获取文章功能")
    @GetMapping("/{categoriesId}/index")
    public ResultVO queryAllArticle(@PathVariable Integer categoriesId) {
        log.debug("正在处理根据分类id获取文章功能,分类id为 {}", categoriesId);

        return blogService.queryAllArticle(categoriesId);

    }



    @ApiOperation("发布文章功能")
    @PostMapping("publish")
    public ResultVO insert(@RequestBody BlogDTO blogDTO) {
        log.debug("用户发布的文章信息 {}", blogDTO);

        return blogService.insert(blogDTO);
    }


    @ApiOperation("根据id显示文章详情功能")
    @GetMapping("{id}/detail")
    public ResultVO detail(@PathVariable Long id) {
        log.debug("正在处理根据id查看文章具体详情功能,id为{}",id);

        return blogService.detailById(id);
    }



    @ApiOperation("获取所有文章类别")
    @GetMapping("/allCategories")
    public ResultVO allCategories() {
        log.debug("正在处理获取文章所有类别请求");

        return blogService.selectAllCategories();
    }


    @ApiOperation("删除文章功能")
    @DeleteMapping("/{id}/delete")
    public ResultVO delete(@PathVariable Long id){
        log.debug("正在处理根据id删除文章请求,id为{}",id);

        return blogService.delete(id);
    }



    @ApiOperation("个人主页我的文章展示")
    @GetMapping("/{id}/selectselfblogs")
    public ResultVO selectSelfBlogs(@PathVariable Long id) {
        log.debug("正在处理个人主页我的文章请求, {}", id);

        return blogService.selectSelfBlogsById(id);
    }

    @ApiOperation("个人主页我赞的文章展示")
    @GetMapping("/{id}/likeblogsall")
    public ResultVO selectLikeBlogsAll(@PathVariable Long id) {
        log.debug("正在处理个人主页点赞的所有文章请求, {}", id);

        return blogService.selectLikeBlogsAllById(id);
    }

    @ApiOperation("个人主页我收藏的文章展示")
    @GetMapping("{id}/collectblogs")
    public  ResultVO selectCollectBlogsAll(@PathVariable Long id) {
        log.debug("正在处理个人主页收藏的所有文章请求, {}", id);

        return blogService.selectCollectBlogsAllById(id);
    }


}













